package com.kws.merchant.controller;


import com.kws.merchant.domain.LogisticsPo;
import com.kws.merchant.domain.Order;
import com.kws.merchant.domain.po.OrderPo;
import com.kws.merchant.domain.vo.OrderStatistics;
import com.kws.merchant.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import com.kws.common.core.domain.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import javax.annotation.Resource;
import java.util.List;

/**
 * 订单(Order)表控制层
 *
 * @author yxy
 * @since 2024-10-22 17:15:43
 */
@RestController
@Api(tags = "订单(Order)")
@RequestMapping("order")
public class OrderController {
    /**
     * 服务对象
     */
    @Resource
    private OrderService orderService;

    @PostMapping("/page")
    @ApiOperation(value = "分页查询列表")
    public R<Page<Order>> pageList(@RequestBody OrderPo order) {
        return R.ok(orderService.pageList(order));
    }

    @GetMapping("/detailById/{id}")
    @ApiOperation(value = "通过主键查询单条数据")
    public R<Order> detailById(@PathVariable Long id) {
        return R.ok(orderService.getById(id));
    }


    @PostMapping("/addOrder")
    @ApiOperation(value = "新增订单")
    public R addOrder(@RequestBody Order order) {
        return R.ok(orderService.addOrder(order));
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改数据")
    public R update(@RequestBody Order order) {
        return R.ok(orderService.updateById(order));
    }


    @PostMapping("/delete")
    @ApiOperation(value = "删除数据")
    public R delete(@RequestBody List<Long> idList) {
        return R.ok(orderService.removeByIds(idList));
    }

    @GetMapping("/list")
    @ApiOperation(value = "商家订单列表")
    public R<List<Order>> listByMerchant() {
        return R.ok(orderService.listByMerchant());
    }

    @GetMapping("/statistics")
    @ApiOperation("待付款、发货、售后、工单巡检统计")
    public R<OrderStatistics> statistics(){
        return R.ok(orderService.statistics());
    }

    @ApiOperation("新增物流编号和设备编号-用户商家填写物流编号时")
    @PostMapping("addLogistic")
    public R addLogistic(@RequestBody LogisticsPo logisticsPo){
        return R.ok(orderService.addLogistic(logisticsPo));
    }


}
